﻿//
// Copyright (c) 2024 BPer
//

#ifndef BPERDECODER_SRC_BPERAUDIODECODERSPEEX_H_
#define BPERDECODER_SRC_BPERAUDIODECODERSPEEX_H_
#include <bperutil/buffer/BPerAudioEncoderBuffer.h>
#include <bperdecoder/BPerAudioDecoder.h>
#include <bperutil/sys/BPerLoadLib.h>
#include <speex/speex.h>

class BPerAudioDecoderSpeex  :public BPerAudioDecoder{
public:
	BPerAudioDecoderSpeex(BPerAudioParam  *pcontext);
	virtual ~BPerAudioDecoderSpeex();
	void init();
	int32_t decode(BPerFrame* pframe,BPerDecoderCallback* pcallback);
private:
	void closedec();
	int32_t isConvert;
	SpeexBits *m_bits;

	BPerLoadLib m_lib;
	void initSpeexPara();
	int32_t m_quality;
	int32_t ret;
	void* m_state;

	int32_t m_channel;
	short *m_out;

	void loadLib();
	void unloadLib();
	const SpeexMode * (*bPer_speex_lib_get_mode) (int32_t mode);
	void *(*bPer_speex_decoder_init)(const SpeexMode *mode);
	void (*bPer_speex_bits_init)(SpeexBits *bits);
	void (*bPer_speex_bits_reset)(SpeexBits *bits);
	int32_t (*bPer_speex_bits_read_from)(SpeexBits *bits, const char *bytes, int32_t len);
	int32_t (*bPer_speex_decode_int)(void *state, SpeexBits *bits, spx_int16_t *out);
	void (*bPer_speex_decoder_destroy)(void *state);
	void (*bPer_speex_bits_destroy)(SpeexBits *bits);
	int32_t (*bPer_speex_decoder_ctl)(void *state, int32_t request, void *ptr);
};

#endif /* BPERDECODER_SRC_BPERAUDIODECODERSPEEX_H_ */
